<template>
    <div>
        <el-card class="box-card">
            <div class="app-container">
                <div class="container-header">
                    <div class="hign-line"></div>
                    <div class="header-left">
                        {{$t('inventoryManagement.baseInfo')}}
                    </div>
                </div>
                <el-form :model="viewModel" ref="queryForm" v-show="showSearch" label-width="88px">
                    <el-row :gutter="24" class="mb8">
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.supplierBatchNo')" prop="supplierBatchNo">
                                EW{{viewModel.lichn}}
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.batch')" prop="batch">
                                EW{{viewModel.lot}}
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierNo">
                                {{viewModel.supplierCode}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                                {{viewModel.materialName}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialNo">
                                {{viewModel.materialCode}}
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.materialType')" prop="materialType">
                                {{viewModel.materialType}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.supplierType')" prop="supplierType">
                                {{viewModel.supplierType}}
                            </el-form-item>
                        </el-col>

                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.incomingQuantity')" prop="incomingQuantity">
                                {{viewModel.batchAmount}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                                {{viewModel.maturity}}
                            </el-form-item>
                        </el-col>
                        <el-col :span="24">
                            <el-form-item :label="$t('inventoryManagement.description')" prop="inspectionExemptionReason" style="width:100%">
                                {{viewModel.description}}
                            </el-form-item>
                        </el-col>

                    </el-row>

                </el-form>
                <div class="container-header">
                    <div class="hign-line"></div>
                    <div class="header-left">
                        {{$t('inventoryManagement.inspectionInfo')}}
                    </div>
                </div>
                <div class="container-table">
                    <el-table max-height="350" border stripe :data="typeList">
                        <el-table-column type="selection" width="55" align="center" />
                        <el-table-column :label="$t('inventoryManagement.inspectionItems')" align="left" prop="projectName" minWidth="160" />
                        <el-table-column :label="$t('inventoryManagement.code')" align="left" prop="projectCode" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.inspectionTypeUnit')" minWidth="130" prop="checkUnit" align="left" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.inspectionType')" minWidth="130" align="left" prop="checkoutTypeCopy" />
                        <el-table-column :label="$t('inventoryManagement.frequency')" minWidth="110" align="left" prop="itemFrequency" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="itemFrequencyValue" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.targetValue')" align="left" prop="targetValue" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.lowerValue')" align="left" prop="lowerLimit" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.upperValue')" align="center" prop="upperLimit" />
                        <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingOne" minWidth="140" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.samplingOptions')" align="left" prop="samplingTwo" minWidth="200">
                            <template slot-scope="scope">
                                <span>{{scope.row.samplingTwo}}</span> <span>{{scope.row.samplingThree}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.samplingQuantity')" align="left" prop="samplingAmount" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.testMethod')" align="left" prop="detectionOne" :minWidth="200" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                <span>{{scope.row.detectionOne}}</span> <span>{{scope.row.detectionTwo}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="symbol" minWidth="110" :show-overflow-tooltip="true" />
                        <el-table-column :label="$t('inventoryManagement.decimalPlaces')" align="left" prop="decimalPlace" :show-overflow-tooltip="true" />
                        <!--                        <el-table-column :label="$t('inventoryManagement.gapValue')" align="left" prop="gap" :show-overflow-tooltip="true" />-->
                    </el-table>

                    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getExtraIInfo" layout="total, sizes, prev, pager, next, jumper" />
                </div>
            </div>
        </el-card>
        <div class="submit-footer">
            <el-button icon="el-icon-close" size="small" @click="closeTab" class="drawer-close">{{$t('public.close')}}</el-button>
        </div>
    </div>

</template>

<script>
import {
    listType,
    getType,
    delType,
    addType,
    updateType,
    refreshCache,
} from '@/api/basic/dict/type'
import { getNoticeList, deleteNotice, readNotice } from '@/api/system/message'

import { getExtraInfo } from '@/api/inventoryManagement/inspectedInventory'
import FileUploadInput from '@/components/FileUploadInput'
export default {
    name: 'inspectionExemption',
    dicts: ['sys_normal_disable'],
    components: {
        FileUploadInput,
    },
    data() {
        return {
            direction: 'rtl',
            code: 'EW',
            addInspectionExemption: false,
            drawer: false,
            approvalOpen: false,
            viewInspectionExemption: false,
            viewModel: {},
            addModel: {},
            viewModel: {
                file: 'xxx.jpeg',
            },
            editModel: {},
            approvalForm: {
                status: '1',
                textarea: '',
            },
            selBtn: 1,
            id: this.$route.params.id,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                noticeTitle: undefined,
                noticeType: undefined,
                hasRead: undefined,
                createTime: undefined,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                materialName: [
                    {
                        required: true,
                        message: this.$t('formValidation.materialNameCannotBeEmpty'),
                        trigger: 'blur',
                    },
                ],
                materialNo: [
                    {
                        required: true,
                        message: '物料编号不能为空',
                        trigger: 'blur',
                    },
                ],
                supplierNo: [
                    {
                        required: true,
                        message: '供应商编号不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
        }
    },
    created() {
        this.getExtraIInfo()
    },
    methods: {
        closeTab() {
            this.$router.push({
                path: '/inventoryManagement/additionalInspection',
            })
        },
        effectDateChange(e, scope) {
            if (parseInt(e) > 0) {
                this.typeList[scope.$index].endDate = this.getNewDay(
                    scope.row.approvalTime,
                    e
                )
            }
        },
        getNewDay(dateTemp, days) {
            var dateTemp = dateTemp.split('-')
            //转换为MM-DD-YYYY格式
            var nDate = new Date(
                dateTemp[1] + '-' + dateTemp[2] + '-' + dateTemp[0]
            )
            var millSeconds = Math.abs(nDate) + days * 24 * 60 * 60 * 1000
            var rDate = new Date(millSeconds)
            var year = rDate.getFullYear()
            var month = rDate.getMonth() + 1
            if (month < 10) month = '0' + month
            var date = rDate.getDate()
            if (date < 10) date = '0' + date
            return year + '-' + month + '-' + date
        },
        fileChange(e) {
            console.log(e)
        },
        drawerClose() {
            this.drawer = false
        },
        /** 查询字典类型列表 */
        getExtraIInfo() {
            this.loading = true
            getExtraInfo(this.id).then((response) => {
                this.loading = false
                if (response.code == 200 && response.data) {
                    this.viewModel = response.data
                    this.typeList = response.data.checkItemList
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getExtraIInfo()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.typeList.push({})
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$modal.msgSuccess('提交成功!')
            this.$router.push({
                path: '/inventoryManagement/additionalInspection',
            })
            // this.$refs['addForm'].validate((valid) => {
            //   if (valid) {
            //     this.$modal.msgSuccess("提交成功!");
            //     this.addInspectionExemption = false;
            //   } else {
            //     console.log('error submit!!');
            //     return false;
            //   }
            // });
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$modal.msgSuccess('发起成功!')
            this.addInspection = false
        },

        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.viewInspectionExemption = true
            //   if(row.hasRead == 0){
            //     readNotice(row.noticeId).then(res=>{
            //       if(res.code == 200){
            //         this.handleQuery()
            //       }
            //     })
            //   }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            this.drawer = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download(
                'system/dict/type/export',
                {
                    ...this.queryParams,
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
    padding-left: 12px;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
    // max-height: calc(100vh - 600px);
    overflow: auto;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.hign-line {
    position: relative;
    left: -8px;
    top: 14px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid #0b7be3;
    float: left;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
.submit-footer {
    height: 52px;
    background: #ffffff;
    box-shadow: 0px -5px 5px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px 4px 0px 0px;
    position: fixed;
    z-index: 9;
    bottom: 0px;
    width: 100%;
    left: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
}
.samplingPercent {
    position: absolute;
    z-index: 9;
    right: 20px;
}
::v-deep .el-card {
    padding-top: 0px;
}
::v-deep .el-form-item__label {
    font-weight: 400;
    color: #999999;
}
</style>
